﻿using AutoMapper;
using MediatR;
using S.EarTag.API.Application.MediatorCommand.ProductionGradingCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IRepository;

namespace S.EarTag.API.Application.MediatorCommandHandler.ProductionGradingCommandHandler
{
    public class ProductionGradingUpdateCommandHandler : IRequestHandler<ProductionGradingUpdateCommand, bool>
    {
        private readonly IProductionGradingRepository _productionGradingRepository;
        private readonly IMapper _mapper;
        public ProductionGradingUpdateCommandHandler(IProductionGradingRepository productionGradingRepository,IMapper mapper)
        {
            _productionGradingRepository = productionGradingRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 修改生产定级信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(ProductionGradingUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _productionGradingRepository.UpdateAsync(_mapper.Map<ProductionGrading>(request));
        }
    }
}
